﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using WFNetLib.WinAPI;

namespace WFNetLib
{
    public class INI
    {
        /// <summary>
        /// INI文件的全路径
        /// </summary>
        public string _iniPath = string.Empty;

        /// <summary>
        /// 类的构造函数，传递INI文件全路径
        /// </summary>
        /// <param name="iniPath">INI文件全路径</param>
        public INI(string iniPath)
        {
            this._iniPath = iniPath;
        }
    # region "对Key的操作"
        /// <summary>
        /// 写INI文件
        /// </summary>
        /// <param name="Section"></param>
        /// <param name="Key"></param>
        /// <param name="Value"></param>
        public void INI_WriteValue(string Section, string Key, string Value)
        {
            Win32API.WritePrivateProfileString(Section, Key, Value, this._iniPath);
        }

        /// <summary>
        /// 读取指定的INI文件
        /// </summary>
        /// <param name="Section"></param>
        /// <param name="Key"></param>
        /// <returns></returns>
        public string INI_ReadValue(string Section, string Key)
        {
            StringBuilder temp = new StringBuilder(255);
            int i = Win32API.GetPrivateProfileString(Section, Key, "", temp, 255, this._iniPath);
            return temp.ToString();
        }

    # endregion
        
    # region "对Section的操作"        

        /// <summary>
        /// 
        /// </summary>
        /// <param name="Section"></param>
        /// <param name="str"></param>
        public void INI_SectionWriteValue(string Section, StringBuilder str)
        {
            Win32API.WritePrivateProfileSection(Section, str, this._iniPath);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="Section"></param>
        /// <returns></returns>
        public string INI_SectionReadValue(string Section)
        {
            StringBuilder temp = new StringBuilder(255);
            long i = Win32API.GetPrivateProfileSection(Section, temp, 255, this._iniPath);
            return temp.ToString();
        }
    # endregion
    }
}
